package utility;

import weka.core.Attribute;
import weka.core.FastVector;
import weka.core.Instance;
import weka.core.Instances;

/**
 * Generates a little ARFF file with different attribute types.
 *
 * @author FracPete
 */
public class AttTest {
    
    public AttTest(){
        
    }
    
    public Instance getInstance(String s){
        Instances data;
        FastVector atts;
        double[] vals;
        int temp;
        //1. set up attributes
        atts = new FastVector();
        for(int i=0;i<s.length();i++){
            temp = i + 1;
            atts.addElement(new Attribute("F" + temp,(FastVector) null));
        }
        
        //2. create instance object
        data = new Instances("MyRelation", atts, 0);
        
        //3. fill with data
        vals = new double[data.numAttributes()];
        for(int i=0;i<s.length();i++){            
            vals[i] = data.attribute(0).addStringValue(s.substring(i, i+1));
        }
        return new Instance(1.0, vals);                
    }
    
    public static void main(String[] args) throws Exception {
        AttTest att = new AttTest();
        Instance temp = att.getInstance("10101010101010");
        System.out.println(temp);
//        FastVector atts;
//        Instances data;        
//        double[] vals;                
//        int i = 0;
//        
//        // 1. set up attributes
//        atts = new FastVector();
//        // - string
//        i++;
//        atts.addElement(new Attribute("att" + i , (FastVector) null));
//        // - string
//        i++;
//        atts.addElement(new Attribute("att" + i, (FastVector) null));
//        // - string
//        i++;
//        atts.addElement(new Attribute("att" + i, (FastVector) null));
//
//        // 2. create Instances object
//        data = new Instances("MyRelation", atts, 0);
//
//        // 3. fill with data
//        // first instance
//        vals = new double[data.numAttributes()];
//        // - string
//        vals[0] = data.attribute(0).addStringValue("1asd");
//        // - string
//        vals[1] = data.attribute(1).addStringValue("2asd");
//        // - string
//        vals[2] = data.attribute(2).addStringValue("3ad");
//        // add
//        data.add(new Instance(1.0, vals));        
//
//        // second instance
//
//        // 4. output data
//        System.out.println(data);
    }
}
